<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
	Message msg = new Message();
	//获取分诊叫号
	String cardno = input.getDesc("cardno","32098119841225396X");//就诊卡号
	if(cardno == null || "".equals(cardno.trim())){
		msg.put("errcode",30041);
		msg.put("errmsg","没有数据");
		out.println(msg);
		return;
	}
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	String date =  sdf.format(new Date());
	
	//查询当前挂号患者的信息
	String baseHql = " select new map(ghhx as ghhx , ghrq as ghrq , ksdm as ksdm , ksmc as ksmc , ysmc as ysmc ,fzbz as fzbz ,hzxm as hzxm ,blh as blh ) from mzjl where jlzt=0 and (cardno ='" + cardno + "' or cardno in(select cardno from SF_BRXXK where sfzh='"+cardno+"') ) and ghrq >'"+date+"' and ghrq <'"+date+"24'";

	List<Map> list = QBuilder.db("basedb").queryHql(baseHql);
	
	if(list == null || list.size() == 0){
		msg.put("errcode",30041);
		msg.put("errmsg","没有数据");
	}else{
		for(Map map : list){
			String count = "0";
			//循环获取当前挂号类别的队列信息
			String ghhx = map.get("ghhx") == null ? "-1" :  map.get("ghhx").toString();
			String ksdm = map.get("ksdm") == null ? "-1" :  map.get("ksdm").toString();
			//分诊标志0:未分诊， 1分诊，2就诊，3结束就诊
			String fzbz = map.get("fzbz") == null ? "-1" :  map.get("fzbz").toString();
			//语句
			String hqlfz ="";
			if("0".equals(fzbz)){//未分诊要查询所有的分诊人数
				hqlfz = "select new map(count(a) as count) from mzjl a where fzbz=1 and ksdm='"+ksdm+"' and jlzt=0 and ghrq >'"+date+"' and ghrq <'"+date+"24' "; 
				
			}else if("1".equals(fzbz)){
				hqlfz = "select new map(count(a) as count) from mzjl a where fzbz=1 and ksdm='"+ksdm+"' and jlzt=0 and ghhx<'"+ghhx+"'   and ghrq >'"+date+"' and ghrq <'"+date+"24' "; 
			}
			if(!"".equals(hqlfz)){
				List<Map> listTemp = QBuilder.db("basedb").queryHql(hqlfz);
				count = listTemp.get(0).get("count").toString();
			}
			map.put("count",count);
			/*
			if(!count.equals("0")){
				//查询当前就诊患者的号码
				hqlfz = "select new map(max(ghhx) as ghhx) from mzjl a where fzbz=2 and ksdm='"+ksdm+"' and jlzt=0 and ghrq >'"+date+"' and ghrq <'"+date+"24' "; 
				List<Map> listTemp = QBuilder.db("basedb").queryHql(hqlfz);
				String maxGhhx = listTemp.get(0).get("ghhx").toString();
				map.put("current_ghhx",maxGhhx);
			}
			*/
		}
		
	
		msg.put("errcode",0);
		msg.put("data",list);
	}
	
	

	out.println(msg);
%>